<div class="Singleform">
<div class="tabs">
<div class="alert alert-info">
  上传变量文件，替换所有变量。
</div>
{{$this->Html->script(array('jquery/jquery.form.js'))}}
<?PHP
	echo $this->MForm->create('Style',array('type'=>'file','id'=>'StyleAdminAddstyleForm','data-noajax'=>true));
?>
        <fieldset>
        <?php
        echo $this->MForm->hidden('id');
        echo $this->MForm->input('name');
        echo $this->MForm->input('slug');
		?>
		<div class="form-group">
			<label class="col-sm-2 control-label" for="StyleVariables">风格variables文件</label>
			<div class="col-sm-10 controls text">
				<input type="file" id="StyleVariables" style="height:32px;" name="data[Style][variables]">
			</div>
		</div>
		<!-- echo $this->MForm->file('variables'); -->
		<?php
		echo $this->MForm->input('css_content');
		echo $this->MForm->hidden('published',array('value'=>1));
        ?>
    <div class="form-group">
    	<label class="col-sm-2 control-label"></label>
    	<div class="col-sm-10 controls"><?php echo $this->MForm->submit(__('Submit'),array('id'=>'btnsubmit') ); ?></div>
    </div>
    </fieldset>
	{{$this->MForm->end()}}
</div>
<script>
$(function(){
	$('#submitStyleVars').click(function(){
		var varform = this.form;
		var postdata = {'Stylevar':{}};
		var haschanged = false;
		$(varform).find('.skey,.sval').each(function(){
			if( $(this).val() != $(this).data('value') ) { // 修改了的才提交
				haschanged = true;
				var index = $(this).data('index');
					postdata['Stylevar'][index] = {
							id:$('input[name="data[Stylevar]['+index+'][id]"]',varform).val(),
							skey:$('input[name="data[Stylevar]['+index+'][skey]"]',varform).val(),
							sval:$('input[name="data[Stylevar]['+index+'][sval]"]',varform).val()
					}
			}
		});
		//console.log(postdata);
		if(haschanged) {
			ajaxAction(varform.action,postdata);
		}
		else{
			alert('没有修改内容，无需提交');
		}		
		return false;
	});
})

</script>
<hr/>
<div class="alert alert-info">
	逐个编辑变量。
</div>
<?php 
echo $this->MForm->create($current_model,array('onsubmit'=>'return false;','data-noajax'=>true));
?>
<table class="table table-striped table-hover">
<thead><tr>
	<th>描述</th><th>变量名</th><th>变量值</th>
</tr>
</thead>
{{loop $styles $key $style}}
	<tr>
	<td>
	{{lang($style['Stylevar']['skey'])}}<br/>
	{{$this->MForm->hidden("Stylevar.$key.id",array('value'=>$style['Stylevar']['id']))}}
	</td>
	<td>{{$this->MForm->input("Stylevar.$key.skey",array('div'=>false,'data-index'=>$key,'label'=>false,'class'=>'form-control skey','data-value'=>$style['Stylevar']['skey'],'value'=>$style['Stylevar']['skey']))}}</td>
	<td>{{$this->MForm->input("Stylevar.$key.sval",array('div'=>false,'data-index'=>$key,'label'=>false,'class'=>'form-control sval','data-value'=>$style['Stylevar']['sval'],'value'=>$style['Stylevar']['sval']))}}</td>
	</tr>
{{/loop}}
</table>
{{$this->MForm->submit('submit',array('id'=>'submitStyleVars') )}}
{{$this->MForm->end()}}
</div>
